<?php
global $IP;
require_once( './includes/WebStart.php' );
require_once($IP.'/includes/SoundShareUtils.php');      

if( !$wgUser->isLoggedIn() || !is_numeric($_GET[type]) || !is_numeric($_GET[id])) die(-1);

$id_user = $wgUser->getId();
$type = (int)$_GET[type];
$artist = mysql_real_escape_string($_GET[artist]);
$artistKey = normalize($artist);
$noartist = mysql_real_escape_string($_GET[noartist]);
$noartistKey = normalize($noartist);
$id = (int)$_GET[id];

if ($id==0) {
	//INSERT NEW
	if ($type==1)
		$noartistfields = "NULL, NULL";
	else
		$noartistfields = "'$noartist', '$noartistKey'";
	$sql = "INSERT IGNORE INTO ss_ilikethis (type, id_user, artist, artistkey, noartist, noartistkey) VALUES ($type, $id_user, '$artist', '$artistKey', $noartistfields )";
} else {
	if ($id>0)
		$sql = "DELETE FROM ss_ilikethis WHERE id_user = $id_user AND id = $id";
	else if ($type==1)
		$sql = "DELETE FROM ss_ilikethis WHERE id_user =  $id_user AND artistKey = '$artistKey' AND type = $type AND noartistKey is null";
	else
		$sql = "DELETE FROM ss_ilikethis WHERE id_user =  $id_user AND artistKey = '$artistKey' AND type = $type AND noartistKey = '$noartistKey'";
}
$dbw =& wfGetDB( DB_MASTER );
$dbw->begin();
$dbw->query( $sql );
$dbw->commit();
